<#assign StringUtils = beansWrapperFn.getStaticModels()["org.apache.commons.lang3.StringUtils"]>
SELECT T.ID
FROM c1_permission t
WHERE T.SITE_ID = :siteId
<#if StringUtils.isNotBlank(typeId)>
AND (T.type_id = :typeId or T.type_code = :typeId)
</#if>
ORDER BY t.order_num,
LENGTH(t.code) DESC
